import axios from 'axios'
import { getCookies } from './auth'
// create an axios instance
const request = axios.create({
  // baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  baseURL: process.env.VUE_APP_BASE_API2,
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})
const Token = getCookies('admin-Token')
// request interceptor
request.interceptors.request.use(
  config => {
    Token && (config.headers['Authorization'] = Token)
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// response interceptor
request.interceptors.response.use(
  response => {
    return response
  },
  error => {
    return Promise.reject(new Error(error))
  }
)

export default request
